package com.platform.common.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;

/**
 * @author klwu
 */
public class JsonUtils {
    public static String toJson(Object obj) {
        Gson gson = new GsonBuilder()
                .setPrettyPrinting()
                .create();
        return gson.toJson(obj);
    }

    public static JsonObject getJsonObj(String json){
        Gson gson = new Gson();
        JsonObject jsonObject = gson.fromJson(json, JsonObject.class);
        return jsonObject;
    }

    public static void main(String[] args) {
        JsonUtils jsonUtils = new JsonUtils();
        JsonObject jsonObj = jsonUtils.getJsonObj("{\"code\":200,\"msg\":\"成功\",\"count\":9,\"data\":null}");
        System.out.println(jsonObj.get("count"));
    }
}
